1. Technical Field
The subject invention relates generally to the field of computers and computer software and, more particularly, to program code conversion methods and apparatus useful, for example, in code translators, emulators and accelerators.
2. Description of Related Art
In both embedded and non-embedded CPU's, one finds predominant Instruction Set Architectures (ISAs) for which large bodies of software exist that could be “accelerated” for performance, or “translated” to a myriad of capable processors that could present better cost/performance benefits, provided that they could transparently access the relevant software. One also finds dominant CPU architectures that are locked in time to their ISA, and cannot evolve in performance or market reach. Such architectures would benefit from “Synthetic CPU” co-architecture.
Program code conversion methods and apparatus facilitate such acceleration, translation and co-architecture capabilities and are addressed, for example, in the co-pending patent application entitled Program Code Conversion, U.S. application Ser. No. 09/827,971.
During program code conversion of a subject program designed for a subject architecture to a target program executable by a target architecture, a problem arises with respect to code that is self-modifying. “Self-modifying code” refers to a subject program that intentionally modifies its own subject code. There are several reasons why a program might modify its own code, where some examples of self-modifying code are listed in Table 1.
TABLE 1Examples of Self-Modifying CodeCodeCode FunctionOverlaysOverlays are a mechanism used by systems that do notsupport virtual memory. To save address space, a singleprocess can re-use a subject address range to hold dif-ferent libraries at different times. Such uses may or maynot be associated with system calls to mmap( ) andmunmap( ).TrampolinesA trampoline is a short section of code constructed inthe data area (i.e., on the stack or in the heap) that con-tains a call to code elsewhere in the system.Code PatchingLinkers and debuggers may modify (patch) existing codeto implement linking or breakpoint operations.Run-TimeThis category includes dynamic binary translators andCompilersjust-in-time (JIT) compilers. Such programs potentiallywrite many fragments of subject code all over the dataarea.Signal HandlerA signal handler for SIGILL (illegal instruction) mightmodify the code that caused the exception and continue.
One of the main problems presented by self-modifying code to dynamic translators is that the subject code that was modified may correspond to target code which has already been translated. When such a modification of the subject code occurs, all translations of the modified subject code must be identified and discarded as stale. Thus, the translator must be able to identify all target code sequences (i.e., translations) that correspond to particular subject code addresses being modified. In dynamic translators, finding and deleting the target code which corresponds to a given subject address is difficult and sometimes not even possible. In some situations, optimizations are applied during translation which yield translations that can no longer be exactly correlated to the range of subject addresses that the translations represent. In these situations, if the subject program modifies its own code at certain subject address, the translator has no way to identify which respective translated target code to invalidate.